<?php

/**
 * Abstract
 * 作者: 魏炎荣
 */
class Controller_Admin_Abstract extends FController
{

    public function beforeAction()
    {
        global $_F;
        define('is_admin',1);
        if($_GET['d']) $this->openDebug();
        $flag = $this->checkAuth();
        if(!$flag) return $flag;
        $_F['in_manage'] = true;
        $_F['s_url'] = 'http://img1.yuanfenba.net';
        $_F['s_url_oss'] = FConfig::get('global.s_url_oss');
        return true;
    }

    protected function checkAuth()
    {
        global $_F;
        $auth_info = Service_Manager::getSessionData();
        if (!$auth_info) {
            Service_Manager::removeSession();
            echo '<script type="text/javascript">top.location.href="http://' . $_F['http_host'] . '/auth/login";</script>';
            return false;
            // header('location:http://aaa.yuanfenba.net/admin/auth/login');
        } else {
            if ($auth_info['status'] != 1) {
                Service_Manager::removeSession();
                echo '<script type="text/javascript">top.location.href="http://' . $_F['http_host'] . '/auth/login";</script>';
                return false;
            }
        }
        $flag = Service_Manager::checkRole();
        if(!$flag){
            $this->error('您没有权限访问');
        }
        return true;
    }

    function showMessage($message, $messageType = 'success', $jumpUrl = null)
    {
        if ($messageType == 'error') {
            $messageType = 'warning';
        }
        $this->assign('messageType', $messageType);
        $this->assign('message_content', $message);
        $this->assign('jump_url', $jumpUrl);
        $this->display('admin/message');
        exit(0);
    }

    function display($tpl = null)
    {
        parent::display(str_replace('admin/', '', $tpl));
    }

}
